<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<script type="text/javascript">
$(document).ready(function() {
	$("#qry_grid").jqGrid( {
		url : '<c:url value="/json/supplierList.do"/>',
		mtype : "POST",
		datatype : "json",
		colNames : [ '供应商代码', '供应商名称'], //
		colModel : [ {
			name : 'supplierID',
			index : 'supplierID',
			width : 100,
			key : true
		}, {
			name : 'companyName',
			index : 'companyName',
			width : 350
		}],
		jsonReader : {
			root : "objList",
			cell : "",
			repeatitems : false,
			id : "uuid"
		},
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		pager : '#qry_pager',
		sortname : 'supplierID',
		viewrecords : true,
		sortorder : "asc",
		caption : "搜索结果",
		ondblClickRow : function(rowid, iRow, iCol, e) {
			qry_select();
		}
	});
	$("#qry_gridpager").jqGrid('navGrid', '#qry_pager', {
		edit : false,
		add : false,
		del : false,
		search : false,
		refresh : false
	});
});

function qry_search() {
	var qry_supplierID = $("#qry_supplierID").val();
	var qry_companyName = $("#qry_companyName").val();
	$("#qry_grid").jqGrid('setGridParam', {
		postData : {
			"paramMap['supplierID']" : qry_supplierID,
			"paramMap['companyName']" : qry_companyName
		},
		page : 1
	}).trigger("reloadGrid");
}

function qry_select() {
	var objId = $("#qry_grid").getGridParam('selrow');
	try {
		if (objId) {
			if ( typeof($("#spId").val()) == "undefined" || $("#spId").val() == ""){
				if($("#supplierIdParam"))
					$("#supplierIdParam").val($("#qry_grid").jqGrid('getCell', objId, 0));
				if($("#supplierCompanyName"))
					$("#supplierCompanyName").val($("#qry_grid").jqGrid('getCell', objId, 1));
				if ( $("#supplierIdParam").val() == "010000" || $("#supplierIdParam").val() == "010001" ){
					 $("#twSupplier").show();
					 if ( $("#twSupplierIdParam").val() == "" ){
						 $("#getTwSupplier").css("display","inline-block");
					 }else{
						 $("#getTwSupplier").hide();
					 }
				}else{
					$("#twSupplierIdParam").val("");
					$("#twSupplier").hide();
				 }
			}else{
				//台湾馆供应商
				$("#" + $("#spId").val()).val($("#qry_grid").jqGrid('getCell', objId, 0));
				$("#" + $("#spName").val()).val($("#qry_grid").jqGrid('getCell', objId, 1));
				if ( $("#" + $("#spId").val()).val() == "010000" || $("#" + $("#spId").val()).val() == "010001" ){
					 $("#twSupplier").show();
					 if ( $("#twSupplierIdParam").val() == ""  ){
						 $("#getTwSupplier").css("display","inline-block");
					 }else{
						 $("#getTwSupplier").hide();
					 }
				}
				$("#spId").val("");
				$("#spName").val("");
			}
			closeDialog();
		} else {
			alert("请选择供应商");
		}
	} catch (e) {
		alert(e);
	}	
	
}

</script>

<div id="qry_dialog" title="搜索供应商">
<table width="350px">
	<tr>
		<td style="width: 95px;">供应商代码</td>
		<td><input name="qry_supplierID" type="text" id="qry_supplierID" size="8" /></td>
	</tr>
	<tr>
		<td style="width: 95px;">供应商名称</td>
		<td><input name="qry_companyName" type="text" id="qry_companyName" size="30" /></td>
	</tr>
	<tr>
		<td colspan="2" align="center">
		<div class="f-link"><a href="javascript:void(0);" onclick=qry_search();return false;>搜索</a></div>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table id="qry_grid"></table>
		<div id="qry_pager"></div>
		</td>
	</tr>
	<tr>
		<td colspan="2" align="center">
		<div class="f-link"><a href="javascript:void(0);" onclick=qry_select();return false;>选择供应商</a></div>
		</td>
	</tr>
</table>
</div>